package ferp.android.views.table.element.image;

import android.content.Context;
import android.graphics.Rect;
import android.widget.ImageView;
import ferp.android.GUI;
import ferp.android.R;
import ferp.android.views.CardView;
import ferp.android.views.table.TableView;
import ferp.android.views.table.element.Element;

/**
 * User: olegs
 * Date: 09/01/2015 08:46
 */
public class Mark extends Element<ImageView>
{
  public Mark(Context context, TableView parent) {super(context, parent);}

  public void layout(Rect area, int player, CardView cv)
  {
    this.area = area;

    int size = GUI.Mark.size();
    int margin = GUI.Mark.margin();
    int left = 0, top = 0;

    switch (player)
    {
      case 0:
        left = cv.getLeft() + margin;
        top = cv.getBottom() - size - margin;

        break;

      case 1:
      case 2:
        left = cv.getRight() - size - margin;
        top = cv.getTop() + margin;

        break;
    }

    area.set(left, top, left + size, top + size);
    layout(area);
  }

  public void show(Rect area, int player, CardView cv)
  {
    layout(area, player, cv);
    show(true);
  }

  @Override
  protected ImageView create(Context context, TableView parent)
  {
    ImageView iv = new ImageView(context);

    iv.setBackgroundResource(R.drawable.mark);

    return iv;
  }
}
